<?php
/*********************/
/*                   */
/*  后台销售统计控制       */
/*   BY voiet        */
/*   2009-9-1更新    */
/*                   */
/*********************/

//require_once( CORE_DIR."/admin/controller/sale/ctl.salescount.php" );
class cct_salescount extends ctl_salescount
{
	
	function countall( )
	{
		
		if ( $_GET['ordertype'] && $_GET['method'] )
		{
				$order['order'] = intval( $_GET['ordertype'] );
				$order['method'] = intval( $_GET['method'] );
		}
		if ( $_GET['searchfrom'] && $_GET['searchto'] )
		{
				$dateFrom = strtotime( $_GET['searchfrom'] );
				$dateTo = strtotime( $_GET['searchto'] );
												
		}
		else
		{
				$dateTo = time();
					$dateFrom = $dateTo-86400*30;
												
		}
		if ( $_GET['dosearch'] )
		{		$search = $_GET['dosearch'];
				$item = $_GET['searchitem'];
		}
		else{
				$search = '';
				$item = '';
		}
		$sales = $this->system->loadmodel( "utility/salescount" );
		$result = $sales->count_all( $dateFrom, $dateTo, $item, $search, $order );
		if ( $_GET['genexml'] == 1 )
		{
			$dataio = $this->system->loadmodel( "system/dataio" );
			$io = "xls";
			$name = array( "商品货号","商品名称", "销售量", "销售额" );
			$dataio->export_begin( $io, $name, "商品销售量(额)", count( $name ) );
			$dataio->export_rows( $io, $result );
		}
		else{
			$this->pagedata['plug'] = "&dosearch=".$_GET['dosearch']."&searchitem=".$_GET['searchitem']."&searchfrom=".$_GET['searchfrom']."&searchto=".$_GET['searchto'];
			$this->pagedata['data'] = $result;
			$this->pagedata['method'] = $_GET['method'];
			$this->page( "sale/count/salescountall.html" );
		}
	}
	
	function membercount( )
	{
			if ( $_GET['ordertype'] && $_GET['method'] )
			{
					$order['order'] = intval( $_GET['ordertype'] );
					$order['method'] = intval( $_GET['method'] );
			}
			if ( $_GET['searchfrom'] && $_GET['searchto'] )
			{
					$dateFrom = strtotime( $_GET['searchfrom'] );
					$dateTo = strtotime( $_GET['searchto'] ) + 86400;
					$memberinfo = $this->system->loadmodel( "utility/salescount" );
					$result = $memberinfo->member_count( $dateFrom, $dateTo, $order );
			}
			else
			{
					$dateTo = time();
					$dateFrom = $dateTo-86400*30;
					
					
			}
			if ( $_GET['dosearch'] )
			{		
					$search = $_GET['dosearch'];
					$item = $_GET['searchitem'];
			}
			else{
				$search = '';
				$item = '';
			}
			$memberinfo = $this->system->loadmodel( "utility/salescount" );
			$result = $memberinfo->member_count( $dateFrom, $dateTo, $item, $search, $order );
			if ( $_GET['genexml'] == 1 )
			{
					$dataio = $this->system->loadmodel( "system/dataio" );
					$io = "xls";
					$name = array( "用户名", "姓名", "销售量", "销售额" );
					$dataio->export_begin( $io, $name, "会员购物量(额)", count( $name ) );
					$dataio->export_rows( $io, $result );
					$dataio->export_finish( $io );
			}
			else
			{
					$this->pagedata['data'] = $result;
					$this->pagedata['method'] = $_GET['method'];
					$this->page( "sale/count/membercount.html" );
			}
	}
	
	function memberregcount( )
	{
			
			if ( $_GET['searchfrom'] && $_GET['searchto'] )
			{
					$dateFrom = strtotime( $_GET['searchfrom'] );
					$dateTo = strtotime( $_GET['searchto'] ) + 86400;
					$memberinfo = $this->system->loadmodel( "utility/salescount" );
					$result = $memberinfo->memberreg_count( $dateFrom, $dateTo, $order );
			}
			else
			{
					$dateTo = time();
					$dateFrom = $dateTo-86400*7;
					
					
			}
			$titletype = array( "byhour" => "小时", "byday" => "日期" , "bymonth" => "月份", "refer_id" => "来源ID", "refer_url" => "来源网址", "b_year" => "出生年份", "area" => "地区");
			if ( $_GET['orderby'] )
			{		
					$order = $_GET['orderby'];
					$title1 = $titletype[$order];
			}
			else{
				$order = 'byday';
				$title1 = '日期';
			}
			$memberinfo = $this->system->loadmodel( "utility/salescount" );
			$result = $memberinfo->memberreg_count( $dateFrom, $dateTo, $order );
			if ( $_GET['genexml'] == 1 )
			{
					$dataio = $this->system->loadmodel( "system/dataio" );
					$io = "xls";
					$name = array( $title1, "会员数");
					$dataio->export_begin( $io, $name, "会员注册统计", count( $name ) );
					$dataio->export_rows( $io, $result );
					$dataio->export_finish( $io );
			}
			else
			{
					$this->pagedata['data'] = $result;
					$this->pagedata['title1'] = $title1;
					$this->pagedata['method'] = $_GET['method'];
					$this->page( "sale/count/memberregcount.html" );
			}
	}
	
	function ordercount( )
	{
			
			if ( $_GET['searchfrom'] && $_GET['searchto'] )
			{
					$dateFrom = strtotime( $_GET['searchfrom'] );
					$dateTo = strtotime( $_GET['searchto'] ) + 86400;
					$orderinfo = $this->system->loadmodel( "utility/salescount" );
					$result = $orderinfo->order_count( $dateFrom, $dateTo, $order );
			}
			else
			{
					$dateTo = time();
					$dateFrom = $dateTo-86400*7;
					
					
			}
			$titletype = array( "byhour" => "小时", "byday" => "日期" , "bymonth" => "月份", "refer_id" => "来源ID", "refer_url" => "来源网址", "shipping" => "配送方式", "itemnum" => "商品数量", "ship_area" => "配送地区", "member_lv_id" => "会员等级", "member_id" => "会员ID","payment" => "支付方式");
			if ( $_GET['orderby'] )
			{		
					$order = $_GET['orderby'];
					$title1 = $titletype[$order];
			}
			else{
				$order = 'byday';
				$title1 = '日期';
			}
			$orderinfo = $this->system->loadmodel( "utility/salescount" );
			$result = $orderinfo->order_count( $dateFrom, $dateTo, $order );
			if ( $_GET['genexml'] == 1 )
			{
					$dataio = $this->system->loadmodel( "system/dataio" );
					$io = "xls";
					$name = array( $title1, "订单数", "订单金额");
					$dataio->export_begin( $io, $name, "订单统计分析", count( $name ) );
					$dataio->export_rows( $io, $result );
					$dataio->export_finish( $io );
			}
			else
			{
					$this->pagedata['data'] = $result;
					if($order=='refer_url')$this->pagedata['data']['mydate'] = $result['mydate'];
					$this->pagedata['title1'] = $title1;
					$this->pagedata['method'] = $_GET['method'];
					$this->page( "sale/count/ordercount.html" );
			}
	}
	
	

}

?>